package com.ruoyi.teach.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.teach.mapper.TeachPlanContentMapper;
import com.ruoyi.teach.mapper.TeachPlanMapper;
import com.ruoyi.teach.domain.TeachPlan;
import com.ruoyi.teach.domain.TeachPlanContent;
import com.ruoyi.teach.service.ITeachPlanService;

/**
 * 教案Service业务层处理
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Service
public class TeachPlanServiceImpl implements ITeachPlanService 
{
    @Autowired
    private TeachPlanMapper teachPlanMapper;
    @Autowired
    private TeachPlanContentMapper teachPlanContentMapper;

    /**
     * 查询教案
     * 
     * @param id 教案ID
     * @return 教案
     */
    @Override
    public TeachPlan selectTeachPlanById(Long id)
    {
        return teachPlanMapper.selectTeachPlanById(id);
    }

    /**
     * 查询教案列表
     * 
     * @param teachPlan 教案
     * @return 教案
     */
    @Override
    public List<TeachPlan> selectTeachPlanList(TeachPlan teachPlan)
    {
        return teachPlanMapper.selectTeachPlanList(teachPlan);
    }

    /**
     * 新增教案
     * 
     * @param teachPlan 教案
     * @return 结果
     */
    @Override
    @Transactional
    public int insertTeachPlan(TeachPlan teachPlan)
    {
    	int count = 0;
        teachPlan.setCreateTime(DateUtils.getNowDate());
        teachPlan.setCreateBy(SecurityUtils.getUsername());
        teachPlanMapper.insertTeachPlan(teachPlan);
        count ++;
        for(int i=0;i<teachPlan.getPeriods();i++) {
        	TeachPlanContent content = new TeachPlanContent();
        	content.setPlanId(teachPlan.getId());
        	content.setPeriod(i+1);
        	content.setObjectives("本课时的教学目标");
        	content.setObjectives("本课时的教学方法");
        	content.setCreateTime(DateUtils.getNowDate());
        	content.setCreateBy(SecurityUtils.getUsername());
        	teachPlanContentMapper.insertTeachPlanContent(content);
        }
        return count;
    }

    /**
     * 修改教案
     * 
     * @param teachPlan 教案
     * @return 结果
     */
    @Override
    public int updateTeachPlan(TeachPlan teachPlan)
    {
        teachPlan.setUpdateTime(DateUtils.getNowDate());
        teachPlan.setUpdateBy(SecurityUtils.getUsername());
        return teachPlanMapper.updateTeachPlan(teachPlan);
    }

    /**
     * 批量删除教案
     * 
     * @param ids 需要删除的教案ID
     * @return 结果
     */
    @Override
    public int deleteTeachPlanByIds(Long[] ids)
    {
        return teachPlanMapper.deleteTeachPlanByIds(ids);
    }

    /**
     * 删除教案信息
     * 
     * @param id 教案ID
     * @return 结果
     */
    @Override
    public int deleteTeachPlanById(Long id)
    {
        return teachPlanMapper.deleteTeachPlanById(id);
    }
}
